(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:TimeslotstlCtrl
     * @description
     * # TimeslotstlCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('TimeslotstlCtrl', TimeslotstlCtrl);

    TimeslotstlCtrl.$inject = ['$scope', 'dataService', 'helper', 'dhfprinterService', '$timeout', '$interval', '$rootScope', '$state', 'moment'];

    function TimeslotstlCtrl($scope, dataService, helper, dhfprinterService, $timeout, $interval, $rootScope, $state, moment) {
        $scope.listAction = function() {
            $scope.getlist();

        }

        $scope.getlist = function() {
            dataService.timeslotstlGet({ schema_id: 0, period_stl_id: 0 }).then(function(re1) {
                if (re1) {
                    $scope.periocd = re1;
                    $scope.deskData = _.sortBy($scope.periocd, 'timeslot_no');
                }
                // console.error("re1", re1, $scope.periocd);
            });
        }

      

        $scope.saveData = function() {
            async.mapValues($scope.deskData, function(data, key, callback) {
                if (!data.timeslot_stl_id) {
                    data.timeslot_no = key;
                    dataService.timeslotstlAdd(data).then(function(r) {
                        callback(null);
                    })
                } else {
                    dataService.timeslotstlUpdate(data).then(function(r) {
                        callback(null);
                    })
                }
            }, function(e, r) {
                helper.myAlert("success", null, null, function() {
                    $state.go("timeslotstl.list");
                });
            });
        }
    }
})();